package com.veo.dao;

import com.veo.domain.Member;
import com.veo.domain.Orders;
import com.veo.domain.Product;
import org.apache.ibatis.annotations.*;


import java.util.List;

public interface OrderDao {

    //查询所有的订单
    @Select("<script>" + "select * from orders "+"<where>"+
            "<if test=\"searcherName!= null and searcherName!=''\"> orderNum like concat(#{searcherName},'%')</if>"+
            "</where>"+
            "</script>")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "orderNum",property = "orderNum"),
            @Result(column = "orderTime",property = "orderTime"),
            @Result(column = "peopleCount",property = "peopleCount"),
            @Result(column = "orderDesc",property = "orderDesc"),
            @Result(column = "payType",property = "payType"),
            @Result(column = "productId",property = "product", javaType = Product.class,one = @One(select = "com.veo.dao.ProductDao.findProductById"))
    })
    List<Orders> findAllOrders(@Param(value = "searcherName") String searcherName);

    //根据id查询订单的所有相关的信息
    @Select("select * from orders where id=#{id}")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "orderNum",property = "orderNum"),
            @Result(column = "orderTime",property = "orderTime"),
            @Result(column = "peopleCount",property = "peopleCount"),
            @Result(column = "orderDesc",property = "orderDesc"),
            @Result(column = "payType",property = "payType"),
            @Result(column = "productId",property = "product", javaType = Product.class,one = @One(select = "com.veo.dao.ProductDao.findProductById")),
            @Result(column = "memberId",property = "member",javaType = Member.class,one = @One(select = "com.veo.dao.MemberDao.findMemberById")),
            @Result(column = "id",property = "travellers",javaType = List.class,many = @Many(select = "com.veo.dao.TravellerDao.findTravellerById")),
    })
    Orders findOrdersById(String id);

    //删除订单
    @Delete("delete from order_traveller where orderId=#{id}")
    int deleteOrderTravellerId(String id);
    @Delete("delete from orders where id=#{id}")
    int deleteOrderById(String id);
}
